<?php
class collection_tmp_class extends Simple_DB 
{
	private $tbl_name = '';
	private $db_name = 'a2417006_app';
	private $db_server_id = 2;
	
	public function __construct($tmp_tbl)
	{
		$this->tbl_name = $tmp_tbl;
		$this->set_db_option($this->db_name, $tmp_tbl, $this->db_server_id);
	}
	
	public function add_tmp_collection_topic($title, $url, $type, $img_url, $datas)
	{
		if(empty($title) || empty($url) || empty($type) || empty($datas['imgs']) || empty($img_url))
		{
			return false;
		}
		
		$tags_hash = md5($url);
		$time = time();
		$sql = "INSERT IGNORE a2417006_app.img_pic_collection_tmp_tbl (sn, tags_hash, url, url_hash, add_time)VALUES";
		$n = 0;
		foreach($datas['imgs'] as $_img_url)
		{
			$_img_url = addslashes($_img_url);
			$url_hash = md5($_img_url);
			if(!empty($_img_url))
			{
				$n ++;
				$sql .= "({$n}, '{$tags_hash}', '{$_img_url}', '{$url_hash}', {$time}), ";
			}
		}
		
		$title = addslashes($title);
		$img_url = addslashes($img_url);
		$sql = trim($sql, ', ')."; INSERT IGNORE a2417006_app.img_topic_collection_tmp_tbl SET tags_hash='{$tags_hash}', add_time={$time}, `type`='{$type}', topic_title='{$title}', img_url='{$img_url}', img_item_count={$n};";
		return db_query_sql($sql, 2, false);
	}
	
	public function get_tmp_topic_list($rows = 100)
	{
		$rows = intval($rows);
		return $this->select(array(), array('order_by'=>'add_time DESC', 'limit'=>"0,{$rows}"));
	}
	
	public function del_topic($tags_hash)
	{
		if(empty($tags_hash) || strlen($tags_hash) != 32)
		{
			return false;
		}
		return $this->delete(array('tags_hash'=>$tags_hash));
	}
	
	public function check_topic_exists($url)
	{
		$hash = md5($url);
		$sql = "select * from a2417006_app.img_topic_collection_tmp_tbl where tags_hash='{$hash}'";
		$r = db_query_sql($sql, 2, false);
		return !empty($r[0]);
	}
}

?>